//
//  ViewController.m
//  JKOCRichText
//
//  Created by 王冲 on 2018/4/27.
//  Copyright © 2018年 希艾欧科技有限公司. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;

    NSMutableAttributedString *attributedString = [self contentOne:@"昨晚进超市，看到了五花八门的水果糖，目不暇接。未品尝便会有一种莫名其妙的甜味充实着味蕾，甜到了心里。现在的孩子们“生在蜜罐里，长在红旗下”，对糖果的的渴求并不十分强烈。" withcontentTwoTextColor:[UIColor redColor] withcontentTwo:@"春天里，万物复苏，田野里，山坡上到处开满了喇叭筒花。长着长形绿色的叶子在地上，托起直立的茎上，茎上顶着几朵美丽的喇叭筒花，花体呈紫红色，喇叭花口处有五片花瓣，在微风中抖动着颤巍巍的身躯，又像一支支喇叭吹响了冲锋的号角。" withcontentTwoTextColor:[UIColor greenColor]];
    
    CGSize size = [JKwideHighSize sizeLabelToFit:attributedString width:JKWidth-40 height:MAXFLOAT];
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, size.width, size.height)];
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor yellowColor];
    label.attributedText = attributedString;
    [self.view addSubview:label];
    
    
}


/**
 学员签到界面的富文本
 */
-(NSMutableAttributedString *)contentOne:(NSString *)string1 withcontentTwoTextColor:(UIColor *)color1 withcontentTwo:(NSString *)string2 withcontentTwoTextColor:(UIColor *)color2{
    
    NSString *hintStr = [NSString stringWithFormat:@"%@%@",string1,string2];
    NSString *author1 = [NSString stringWithFormat:@"%@",string1];
    NSString *author2 = [NSString stringWithFormat:@"%@",string2];
    
    NSRange authrange1 = [hintStr rangeOfString:author1];
    NSRange authrange2 = [hintStr rangeOfString:author2];
    
    NSMutableAttributedString *attributehintStr = [[NSMutableAttributedString alloc]initWithString:hintStr];
    
    /** 颜色设置*/
    [attributehintStr addAttribute:NSForegroundColorAttributeName value:color1 range:authrange1];
    [attributehintStr addAttribute:NSForegroundColorAttributeName value:color2 range:authrange2];
    /** 大小设置*/
    [attributehintStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:authrange1];
    [attributehintStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:authrange2];
    
    return attributehintStr;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
